import Layout from '@/layout'
import { getMenu } from '@/api/user'

export async function getMenuNew() {
  const resulet = await getMenu({ staffId: sessionStorage.getItem('didiCarStaffId') })
  // 获取菜单失败
  if (resulet.code !== 200) return this.$message('获取失败')
  var newMenu = []
  for (const item of resulet.data) {
    const children = []
    if (item.children.length <= 1) {
      newMenu.push({
        path: item.path,
        component: Layout,
        name: item.name,
        alwaysShow: true,
        meta: { title: item.label, icon: item.icon },
        // redirect: `${item.path}/index`,
        children: [
          {
            path: item.children[0].path,
            component: (resolve) => require([`@/views/${item.children[0].links}.vue`], resolve),
            name: item.children[0].name,
            meta: { title: item.children[0].label }
          }
        ]
      })
    } else {
      for (let i = 0; i < item.children.length; i++) {
        children.push({
          path: item.children[i].path,
          component: (resolve) => require([`@/views/${item.children[i].links}.vue`], resolve),
          name: item.children[i].name,
          meta: { title: item.children[i].label }
        })
      }
      newMenu.push({
        path: item.path,
        component: Layout,
        name: item.name,
        // redirect: `${item.path}/index`,
        meta: { title: item.label, icon: item.icon },
        children
      })
    }
  }
  // console.log(newMenu, 47)
  return newMenu
}

